using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;
public partial class admin_A_phieuDeal : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
            LoaData();
            LoadDropDownList();
        }
        
    }
    private void LoadDropDownList()
    {

        TinhTrang_PhieuCollection tinhTrangPhieuCollection = TinhTrang_Phieu_BUS.GetAll();
        ddl_TinhTrangPhieu.DataTextField = TinhTrang_PhieuColumns.TenTinhTrang.ToString();
        ddl_TinhTrangPhieu.DataValueField = TinhTrang_PhieuColumns.MaTinhTrang_Phieu.ToString();
        ddl_TinhTrangPhieu.DataSource = tinhTrangPhieuCollection;
        ddl_TinhTrangPhieu.DataBind();
        ddl_TinhTrangPhieu.Items.Insert(0, new ListItem("All", ""));

    }

    private void LoaData()
    {
        PagerV2_8_1.PageSize = 10;
        Criteria c = new Criteria();
        if (txt_MaPH.Text != "")
        {
            c.add(Condition.AND, PhieuDealColumns.ID, Condition.LIKE, txt_MaPH.Text);
        }
        int total = 0;
        PhieuDealCollection phieuDealCollection =
            Phieu_Deal_BUS.Get(c.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize,
            PhieuDealColumns.ID.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = phieuDealCollection;
        Repeater1.DataBind();

        PagerV2_8_1.ItemCount = total;
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            Phieu_Deal_DTO phieuDeal = (Phieu_Deal_DTO)e.Item.DataItem;

            HyperLink hyp_MaPH = (HyperLink)e.Item.FindControl("hyp_MAPHIEU");
            //HyperLink hyp_MaMH = (HyperLink)e.Item.FindControl("hyp_MATHANG");

            Literal tinh_trang = (Literal)e.Item.FindControl("l_tinhtrang");
            TinhTrang_Phieu_DTO tinhTrang = TinhTrang_Phieu_BUS.GetByID(phieuDeal.MaTinhTrang_Phieu);
            Literal don_Hang = (Literal)e.Item.FindControl("l_DonHang");
            CTHoaDon_DTO donHang = CTHoaDon_BUS.GetByID(phieuDeal.MaCTHD);

            tinh_trang.Text = tinhTrang.TenTinhTrang;
            don_Hang.Text = donHang.ID.ToString();
            //hyp_MaPH.Text = phieuDeal.MaPhieu.ToString();
            //hyp_MaMH.Text = phieuDeal.MaMH.ToString();
            HyperLink hplsua = (HyperLink)e.Item.FindControl("hpl_Edit");
            hplsua.NavigateUrl = "~/admin/A_phieuDeal_Update.aspx?ID=" + phieuDeal.ID.ToString();
            //hyp_MaMH.NavigateUrl = "~/admin/A_Mathang.aspx?MaMH=" + phieuDeal.MaMH.ToString();
            hyp_MaPH.NavigateUrl = "~/admin/A_chitiet_phieuDeal.aspx?ID=" + phieuDeal.ID.ToString();
        }
    }
    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoaData();
    }
}
